// router/index.js
import { createRouter, createWebHistory } from "vue-router";
import Home from "../pages/Home.vue";
import User from "../pages/User.vue";
import Add from "../pages/Add.vue";
import { usePageStore } from "../stores/pageStore";

const routes = [
  {
    path: "/",
    redirect: "/home",
  },
  {
    path: "/home",
    component: Home,
  },
  {
    path: "/user",
    component: User,
  },
  {
    path: "/add",
    component: Add,
  },
];

const router = createRouter({
  history: createWebHistory(),
  routes,
});

const pageStore = usePageStore();

router.beforeEach((to, from, next) => {
  pageStore.updatePage(to.path);
  next();
});

export default router;
